﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MediaPortal.GUI.Library;
using MediaPortal.Dialogs;


namespace NotificationTester
{
    public class MyPlugin : GUIWindow, ISetupForm
    {
        const int _windowID = 0; // WindowID of windowplugin belonging to this setup. Enter your own unique code
        System.Timers.Timer t = new System.Timers.Timer(15000);
        MPNotificationBar.INotification notification;

        public MyPlugin()
        {
            //Start ProgressBar Example
            ProgressBarExample _ProgressBarExample = new ProgressBarExample();

            //Start TimeoutMessage Example
            TimeoutMessageExample _TimeoutMessageExample = new TimeoutMessageExample();
        }

        #region ISetupForm Members
        // Returns the name of the plugin which is shown in the plugin menu
        public string PluginName()
        {
            return "MyFirstPlugin";
        }

        // Returns the description of the plugin is shown in the plugin menu
        public string Description()
        {
            return "My First Plugin";
        }

        // Returns the author of the plugin which is shown in the plugin menu
        public string Author()
        {
            return "YourNameHere";
        }

        // show the setup dialog
        public void ShowPlugin()
        {
            MessageBox.Show("Nothing to configure, this is just an example");
        }

        // Indicates whether plugin can be enabled/disabled
        public bool CanEnable()
        {
            return true;
        }

        // Get Windows-ID
        public int GetWindowId()
        {
            return _windowID;
        }

        // Indicates if plugin is enabled by default;
        public bool DefaultEnabled()
        {
            return true;
        }

        // indicates if a plugin has it's own setup screen
        public bool HasSetup()
        {
            return true;
        }

        /// <summary>
        /// If the plugin should have it's own button on the main menu of MediaPortal then it
        /// should return true to this method, otherwise if it should not be on home
        /// it should return false
        /// </summary>
        /// <param name="strButtonText">text the button should have</param>
        /// <param name="strButtonImage">image for the button, or empty for default</param>
        /// <param name="strButtonImageFocus">image for the button, or empty for default</param>
        /// <param name="strPictureImage">subpicture for the button or empty for none</param>
        /// <returns>true : plugin needs it's own button on home
        /// false : plugin does not need it's own button on home</returns>
        /// 
        public bool GetHome(out string strButtonText, out string strButtonImage,
            out string strButtonImageFocus, out string strPictureImage)
        {
            strButtonText = String.Empty;
            strButtonImage = String.Empty;
            strButtonImageFocus = String.Empty;
            strPictureImage = String.Empty;
            return false;
        }

        // With GetID it will be an window-plugin / otherwise a process-plugin
        public override int GetID
        {
            get
            {
                return _windowID;
            }

            set
            {
            }
        }

        #endregion
    }

    public class TimeoutMessageExample
    {
        Int32 _PluginID = 0;
        Int16 _SecondsToLive = 30; //seconds

        public TimeoutMessageExample()
        {
            //Add notification to NotificationBarManager
            MPNotificationBar.INotification _Notification = MPNotificationBar.NotificationBarManager.AddNotification(_PluginID, "This will disappear in " + _SecondsToLive +  " seconds...", MPNotificationBar.NotificationBarManager.Types.Information);
            _Notification.SecondsToLive = _SecondsToLive;
        }
    }

    public class ProgressBarExample
    {
        Int32 _PluginID = 0;
        System.Timers.Timer _DownloadTimer;
        MPNotificationBar.INotification _Notification;

        public ProgressBarExample()
        {
            //Add notification to NotificationBarManager
            _Notification = MPNotificationBar.NotificationBarManager.AddNotification(_PluginID, "Downloading...", MPNotificationBar.NotificationBarManager.Types.Information, true, true);

            //Emulate a download progress stepping 1% every second
            _DownloadTimer = new System.Timers.Timer(1000);
            _DownloadTimer.Elapsed += new System.Timers.ElapsedEventHandler(t_Elapsed);
            _DownloadTimer.Enabled = true;
            _DownloadTimer.Start();
        }

        void t_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            //Step 1%
            _Notification.Progress++;

            //If download is finished -> mark notification for removal
            if (_Notification.Progress > 100)
            {
                _Notification.Remove = true;
                _DownloadTimer.Stop();
            }
        }
    }
}
